From first commit to advanced collaboration: internalize version control mental models, branching strategies, rebasing, code review discipline, release management, and contribution excellence.
Internal state machine thinking > memorizing commands.
Git stores snapshots (blobs) referenced by trees, pointed to by commits. Branch = movable pointer to a commit. HEAD = current reference.
Acts as a curated snapshot in progress. You choose git add granularity β commit exactly what matters.
Modified (working tree) β Staged (index) β Committed (repository). Understand transitions.
Commit IDs immutably bind content + parents + author + time. Rewriting history creates new hashes.
git init
git status
git add README.md
git commit -m "feat: initial commit"
# Link remote
git remote add origin https://github.com/user/repo.git
git push -u origin main
git status + git log --oneline --graph --decorate --all as a dashboard.git reflog to recover from resets/amend mistakes.Branch strategy = collaboration contract.
develop, separate release/hotfix branches.Feature branch history (rebased):
A -- B -- C (main)
\
d' -- e' -- f' (feature)
Feature branch history (merged):
A -- B -- C (main) -- M
\ /
d -- e -- f (feature)
# After pulling or rebasing
# 1. Examine status
git status
# 2. Open conflict markers in files
# 3. Decide keep ours/theirs or manual merge
# 4. Stage resolved files
git add file.js
# 5. Continue
# merge: git commit
# rebase: git rebase --continue
# 6. Final validation tests + push
PR quality & review discipline accelerate teams.
Atomic scope, descriptive title, clear context, test evidence, checklist of impacts.
Example: feat(parser): support streaming tokens β type(scope): summary.
Map each change to a tracked issue β traceability, planning accuracy, automated closure.
Optimize for clarity, risk reduction, and teaching. Ask why not just what changed.
git tag -a v1.4.0 -m "Release v1.4.0"Rewrite, optimize, debug repository state with precision.
Reorder, squash, reword commits: git rebase -i HEAD~7 β curated history.
Binary search history: git bisect start β mark good/bad commits β pinpoint regression.
Use sparingly. Prefer package registries or monorepo subsets. If used: pin SHAs, document update flow.
Single commit forward-port/backport. Keep metadata; avoid divergence storms.
# Oops after reset --hard
# 1. Show movement history
git reflog
# 2. Checkout lost commit
git checkout <commit-sha>
# 3. Restore branch pointer
git branch recovered-work
# 4. Continue safely
# Interactive rebase last N commits
git rebase -i HEAD~5
# Change 'pick' to 'squash' or 'fixup' accordingly
# Force push only if branch not shared or after team agreement
Experiment with mental models locally in your browser.
Enter commit messages separated by newlines. We'll simulate a linear history; then branch.
Simulates conflicting edits to same line.
High-frequency reference organized by intent.
git config --global user.name "Your Name"
git config --global user.email you@example.com
git init
.gitignore
git log --oneline --graph --decorate --all
git show <commit>
git diff HEAD~2..HEAD
git add -p
git commit -m "feat: msg"
git restore --staged file.js
git stash push -m "ctx"
git stash list
git switch -c feature/x
git merge main
git rebase main
git cherry-pick <sha>
git commit --amend
git reset --soft HEAD~1
git revert <sha>
git reflog
git gc --aggressive --prune=now
git clean -fd
Solidify mastery through reflective practice.
It rewrites commit hashes; collaborators' histories diverge causing forced pushes & potential lost work if not coordinated.
Soft: move HEAD only; index + working keep changes. Mixed (default): reset index, keep working tree. Hard: reset index & working β discards changes.
On public history: revert creates a new commit negating changes preserving auditability; reset rewrites history.
Authenticity & non-repudiation; prevents impersonation in sensitive repos.